#include <iostream>
#include <stdlib.h>
using std::cout;
using std::endl;

class Singleton
{
public:
    static Singleton* getInstance(){
        if(_pInstance == nullptr){
            atexit(destroy);
            _pInstance = new Singleton(1,2);
        }
        cout << "Singleton* getInstance()"<< endl;
        return _pInstance;
    }

    void init(int x,int y){
        _ix = x;
        _iy = y;
    }

    void print(){
        cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }

private:
    static void destroy(){
        if(_pInstance){
            delete _pInstance;
            _pInstance = nullptr;
        }
    }

    Singleton() = default;

    Singleton(int x,int y)
    :_ix(x)
    ,_iy(y)
    {
        cout << "Singleton(int,int)" << endl;
    }

    ~Singleton(){
        cout << "~Singleton()" << endl;
    }

    Singleton(const Singleton & rhs) = delete;
    Singleton &operator=(const Singleton & rhs) = delete;

private:
    int _ix;
    int _iy;
    static Singleton* _pInstance;
};

//Singleton* Singleton::_pInstance = nullptr;
Singleton* Singleton::_pInstance = getInstance();


void test0(){
    Singleton::getInstance()->init(88,88);
    Singleton::getInstance()->print();

}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


